<?php

class user_oauthModel extends Model {
    const QQ=1;
    const WEIBO=2;
    const WEIXIN=3;
    const MINIWX=4;
    
    public function countByDay($oauth_id) {
        $sql = "select date(`add_time`) as total from `wf_user_oauth` where oauth_id={$oauth_id} GROUP BY date(`add_time`) ";
        $result = $this->query($sql)->fetchAll();
        return count($result);
    }
    
    public function getType() {
        return [
            1 => 'QQ',
            2 => '微博',
            3 => '微信',
            4 => '小程序'
        ];
    }
    
    public function groupByDay($oauth_id, $page, $page_size) {
        $limit = ($page-1)*$page_size;
        $sql = "select date(`add_time`) as day,count(`uid`) as total from `wf_user_oauth` where oauth_id={$oauth_id} GROUP BY date(`add_time`) limit {$limit}, {$page_size}";
        $result = $this->query($sql)->fetchAll();
        $data = array();
        if($result) {
            foreach($result as $row) {
                $data[$row['day']] = $row['total'];
            }
        }
        return $data;
    }
}